package com.work.music.controller;

import com.work.music.common.ResponseJson;
import com.work.music.exception.AjaxOperationFailException;
import com.work.music.utils.FileUploadUtil;
import com.work.music.utils.StringUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * Created by xs on 2019/4/13.
 */
@RestController
public class UploadController {
    /**
     * 上传图片
     * @param img
     * @return
     * @throws AjaxOperationFailException
     */
    @RequestMapping("/app/uploadimg")
    public ResponseJson uploadImg(MultipartFile img) throws AjaxOperationFailException {
        String imgUrlStr = "";
        if(img != null) imgUrlStr = FileUploadUtil.uploadImage(img, "music/");
        ResponseJson responseJson = new ResponseJson();
        responseJson.setObj(StringUtil.IMGURL + imgUrlStr);
        return responseJson;
    }
}
